<?php
/**
 * Created by PhpStorm.
 * User: a
 * Date: 2016/6/2
 * Time: 17:17
 */

namespace Admin\Model;
use Think\Model;

class UserinfoModel extends Model{
    protected $trueTableName = 'bypal_comm_user';

    /**
     * 查询用户
     * @return mixed
     */
    public function get_user_info($user_name,$user_phone,$role_id){
        $sql="select t1.user_id,t1.user_name,t1.load_name,t3.role_name,t1.user_phone,IFNULL(t5.fac_simple_name,'未关联商户') fac_simple_name from bypal_comm_user t1
        left join bypal_comm_userrole t2 on t1.user_id=t2.user_id
        left join bypal_comm_role t3 on t2.role_id=t3.role_id
        left join bypal_comm_userfac t4 on t1.user_id=t4.user_id
        left join bypal_facilitator_info t5 on t4.fac_id=t5.id where 1=1";

        if($user_name!=''){
            $sql.=" and t1.user_name like '%$user_name%'";
        }
        if($user_phone!=''){
            $sql.=" and t1.user_phone ='$user_phone'";
        }
        if($role_id!=''){
            $sql.=" and t2.role_id ='$role_id'";
        }

        $Model = new \Think\Model();
        $values=$Model->query($sql);
        return $values;
    }

    public function get_user_by_name($load_name,$user_id){
        $sql="select user_id,user_name,load_name from bypal_comm_user where load_name='$load_name'";
        if($user_id!=''){
            $sql.=" and user_id!=$user_id";
        }
        $Model = new \Think\Model();
        $values=$Model->query($sql);
        return $values;
    }

    public function get_user_by_id($user_id){
        $sql="select t1.user_id,t1.user_name,t1.user_phone,t2.role_id,t1.load_name,t3.fac_id,t4.fac_simple_name from bypal_comm_user t1
        left join bypal_comm_userrole t2 on t1.user_id=t2.user_id
        left join bypal_comm_userfac t3 on t1.user_id=t3.user_id
        left join bypal_facilitator_info t4 on t3.fac_id=t4.id where t1.user_id='$user_id'";
        $Model = new \Think\Model();
        $values=$Model->query($sql);
        return $values;
    }

    public function get_login($load_name,$password){
        $sql="select t1.user_id,t1.user_name,t2.role_id from bypal_comm_user t1
        left join bypal_comm_userrole t2 on t1.user_id=t2.user_id where t1.load_name='$load_name' and t1.load_pwd='$password'";
        $Model = new \Think\Model();
        $values=$Model->query($sql);
        return $values;
    }
}